<template>
  <div class="home">
    <van-search
      v-model="value"
      show-action
      label="地址"
      placeholder="请输入搜索关键词"
      @search="onSearch"
    >
      <template #action>
        <div @click="onSearch">搜索</div>
      </template>
    </van-search>
    <div class="main">
      <dl
        v-for="(item, index) in list"
        :key="index"
        @click="goTodetail(item.id)"
      >
        <dt>
          <img :src="item.img" alt="" />
        </dt>
        <dd>
          <p>
            {{ item.title }}
          </p>
          <p>
            {{ item.money }}
          </p>
        </dd>
      </dl>
    </div>
  </div>
</template>

<script>
import { getList } from "../../../api/index";
export default {
  name: "home",

  data() {
    return {
      list: [],
      value: "",
    };
  },

  mounted() {},

  methods: {
    goTodetail(id) {
      console.log(id);
      this.$router.push({
        path: "/detail",
        query: {
          id: id,
        },
      });
    },
    onSearch(val) {
      console.log(val);
    },
  },
  created() {
    getList().then((res) => {
      this.list = res.data.data;
      // console.log(res.data.data);
    });
  },
};
</script>

<style lang="scss" scoped>
.main {
  width: 100%;
  padding: 10px;
  dl {
    width: 50%;
    height: 250px;
    text-align: center;
    float: left;
  }
}
</style>